package com.geek.factory.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.geek.factory.entity.DeviceRepairApprovalLog;
import com.geek.factory.vo.DeviceRepairApprovalLogVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface DeviceRepairApprovalLogMapper  extends BaseMapper<DeviceRepairApprovalLog> {


    @Select("<script>" +
            "SELECT l.*, r.device_name, r.device_type, pl.line_name " +
            "FROM device_repair_approval_log l " +
            "LEFT JOIN device_repair_report r ON l.report_id = r.id " +
            "LEFT JOIN product_line pl ON r.product_line_id = pl.id " +
            "WHERE 1=1 " +
            "<if test='deviceName != null and deviceName != \"\"'>AND r.device_name LIKE CONCAT('%', #{deviceName}, '%') </if>" +
            "<if test='approver != null and approver != \"\"'>AND l.approver LIKE CONCAT('%', #{approver}, '%') </if>" +
            "<if test='decision != null and decision != \"\"'>AND l.decision = #{decision} </if>" +
            "ORDER BY l.approval_time DESC" +
            "</script>")
    IPage<DeviceRepairApprovalLogVO> selectPagedWithDetails(
            Page<DeviceRepairApprovalLogVO> page,
            @Param("deviceName") String deviceName,
            @Param("approver") String approver,
            @Param("decision") String decision
    );












}
